package com.ruiysoft.controller.order.util;

import com.ruiysoft.controller.order.vo.OrderListCusVo;
import com.ruiysoft.service.order.bean.OrderDto;
import com.ruiysoft.util.CurrencyUtils;
import com.ruiysoft.util.DateFormatUtil;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * Date : 2018/11/27
 *
 * @author WenJialu
 */
public enum OrderShopUtil {

	INSTANCE;


	public List<OrderListCusVo> orderDtos2OrderListCusVos(List<OrderDto> dtos) {
		return Optional.ofNullable(dtos)
				.map(ds ->
						ds.stream().map(this::orderDto2OrderListCusVo).collect(Collectors.toList()))
				.orElse(Collections.emptyList());
	}

	private OrderListCusVo orderDto2OrderListCusVo(OrderDto dto) {
		return Optional.ofNullable(dto)
				.map(OrderDto::getOrderMain)
				.map(om ->
						new OrderListCusVo().id(om.getId())
								.orderNo(om.getOrderNo())
								.createTime(DateFormatUtil.INSTANCE.SDF_UNTIL_MIN.format(om.getCreateTime()))
								.collectedAmount(CurrencyUtils.INSTANCE.cent2Yuan(om.getCollectedAmount()))
								.status(om.getStatus())
								.skuInfoList(OrderWechatUtil.INSTANCE.orderSkuDtos2OrderSkuListCusVos(dto.getOrderSkuDtos())))
				.orElse(null);
	}
}
